#include <bits/stdc++.h>
// 2025/07/20
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

string s;
char st1[101];
int top1, top2, st2[101];
vector<char> v;

int help(char op)
{
    if (op == '+' || op == '-')
        return 1;
    if (op == '*' || op == '/')
        return 2;
    if (op == '^')
        return 3;
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    int n = s.size();

    for (int i = 0; i < n; i++) {
        if (isdigit(s[i])) {
            v.push_back(s[i]);
        } else if (s[i] == '(') {
            st1[++top1] = s[i];
        } else if (s[i] == ')') {
            while (top1 > 0 && st1[top1] != '(') {
                v.push_back(st1[top1]);
                top1--;
            }
            if (top1 > 0 && st1[top1] == '(') {
                top1--;
            }
        } else {
            while (top1 > 0 && st1[top1] != '(' && (help(s[i]) < help(st1[top1]) || (help(s[i]) == help(st1[top1]) && s[i] != '^'))) {
                v.push_back(st1[top1]);
                top1--;
            }
            st1[++top1] = s[i];
        }
    }

    while (top1 > 0) {
        v.push_back(st1[top1]);
        top1--;
    }

    for (auto x : v)
        cout << x << " ";
    cout << endl;

    for (int i = 0; i < v.size(); i++) {
        if (isdigit(v[i])) {
            st2[++top2] = v[i] - '0';
        } else {
            int a = st2[top2--];
            int b = st2[top2--];
            if (v[i] == '+')
                st2[++top2] = b + a;
            else if (v[i] == '-')
                st2[++top2] = b - a;
            else if (v[i] == '*')
                st2[++top2] = b * a;
            else if (v[i] == '/')
                st2[++top2] = b / a;
            else if (v[i] == '^')
                st2[++top2] = pow(b, a);
            for (int j = 1; j <= top2; j++)
                cout << st2[j] << " ";
            for (int j = i + 1; j <= v.size(); j++)
                cout << v[j] << " ";
            cout << endl;
        }
    }
    return 0;
}